home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
9536
/
9536.xpi
/
chrome
/
commentsbar_ff.jar
/
content
/
commentsbar_ff
/
widget.js
< prev
Wrap
Text File
|
2008-12-22
|
11KB
|
286 lines
var oldValue = 300;
var alwaysOnTopState = false;
var isMaximized = true;
var captionSize = 24;
var isBorder = false;
var tool = null;
var ie = true;
function ToolBarInit(_tool)
{
tool = _tool;
ie = false;
onReady();
}
function GetProperty(name, value)
{
if (tool)
{
return tool.getProperty(name, value);
} else
return window.external.GetProperty(name, value);
}
function SetProperty(name, value)
{
if (tool)
{
return tool.setProperty(name, value);
} else
return window.external.SetProperty(name, value);
}
function AlwaysOnTopTriger() {
AlwaysOnTop(alwaysOnTopState);
alwaysOnTopState = !alwaysOnTopState;
}
function AlwaysOnTop(b) {
try{
if (b) window.external.SetWindowPos(-2, 0, 0, 0, 0, 3);
else window.external.SetWindowPos(-1, 0, 0, 0, 0, 3);
} catch (err) {}
}
function MinimizeMaximizeTriger() {
if (isMaximized) {
Minimize();
}
else {
Maximize();
}
isMaximized = !isMaximized;
}
function BorderTriger() {
if (isBorder) {
BorderOff();
}
else {
BorderOn();
}
isBorder = !isBorder;
}
function BorderOn() {
try{
//WS_THICKFRAME, SWP_FRAMECHANGED
window.external.ModifyStyle(0, 262144, 32);
} catch (err) {}
return false;
}
function BorderOff() {
try{
//WS_THICKFRAME, SWP_FRAMECHANGED
window.external.ModifyStyle(262144,0, 32);
} catch (err) {}
return false;
}
function Minimize() {
if (tool)
{
var size = tool.getSize();
oldValue = size[1];
tool.resize(size[0], captionSize);
} else {
try{
window.external.GetWindowRect(function(left, top, right, bottom) {
oldValue = bottom - top;
if (oldValue < 100) oldValue = 100;
window.external.MoveWindow(left, top, right - left, captionSize);
moveSmoothCorner(right - left, captionSize);
document.getElementById("_content").style.display = "none";
});
} catch (err) {}
}
return false;
}
function Maximize() {
if (tool)
{
var size = tool.getSize();
tool.resize(size[0], oldValue);
} else {
try{
window.external.GetWindowRect(function(left, top, right, bottom) {
window.external.MoveWindow(left, top, right - left, oldValue);
moveSmoothCorner(right - left, oldValue);
document.getElementById("_content").style.display = "block";
});
} catch (err) {}
}
return false;
}
function Close() {
if (tool)
{
tool.close();
} else
try{
setTimeout("smoothChangeTransparency(220, 0, -10)", 10);
setTimeout("window.external.Close()", 210);
} catch (err) {}
return false;
}
function Capturemouse() {
try{
window.external.Capturemouse();
} catch (err) {}
}
function whichElement(e) {
if (tool)
{
tool.captureMouse(e);
return;
}
var targ
if (!e) var e = window.event
if (e.target) targ = e.target
else if (e.srcElement) targ = e.srcElement
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode
var tname
tname = targ.tagName
if (tname != "INPUT") Capturemouse()
}
function smoothChangeTransparency(from, to, step)
{
try
{
from += step;
from = (from > 255) ? 255 : ((from < 0)? 0 : from);
window.external.MakeWindowTransparent(0xEEFF00, from);
if ((step>0 && from<=to) || (step<0 && from>=to))
setTimeout("smoothChangeTransparency("+from+","+to+","+step+")", 10);
} catch (err) {}
}
function onReady(){
try
{
//BorderTriger();
var userVarsStr = GetProperty("user_vars","");
placeWindowButtons(true, userVarsStr, !tool, true);
document.getElementById("_header").innerHTML = GetProperty("caption","");
if (!tool)
{
AlwaysOnTopTriger();
window.external.MakeWindowTransparent(0x00FFEE, 0);
placeSmoothCorner();
}
if (userVarsStr && (GetProperty("first_start","true") == "true"))
{
showSettings();
} else {
showContent(false);
}
if (!tool)
{
window.external.Show();
setTimeout("smoothChangeTransparency(0, 220, 150)", 10);
}
} catch (err) {}
}
function prepeareString($0, $1)
{
return GetProperty($1, $1);
}
function prepeareWidget(src)
{
return src.replace(/\[\[(\w*?)\]\]/ig, prepeareString);
}
function showSettings()
{
var userVarsStr = GetProperty("user_vars","");
if (userVarsStr)
{
var userVars = eval("(" + userVarsStr + ");");
var html = "<center><table>";
for(variable in userVars)
{
html += "<tr><td class='name_field'>" + userVars[variable].screenName + "</td>";
if (userVars[variable].type == "enum")
{
html += "<td><SELECT class='input_field' id='"+variable+"'>";
for(val in userVars[variable].values)
{
html += "<OPTION value='"+val+"'";
if (val == GetProperty(variable,""))
html += ' SELECTED';
html += ">"+userVars[variable].values[val]+"</OPTION>";
}
html += "</SELECT></TD>";
} else {
html += "<td><input type='text' class='input_field' id='"+variable+"' value='"+GetProperty(variable,"")+"'></td>";
}
}
html += "</tr>";
html += "<tr><td colspan=2 align=right>";
html += "<input type=button value='Cancel' class='save_button' onClick='javascript:showContent(false);'>";
html += "<input type=button value='Save' class='save_button' onClick='javascript:showContent(true);'></td></tr>";
html += "</table>";
document.getElementById("_content").innerHTML = html;
}
}
function showContent(first_start)
{
if(first_start)
{
var fields = document.getElementsByTagName('input');
for (i=0; i<fields.length; i++) {
SetProperty(fields[i].id, fields[i].value);
}
fields = document.getElementsByTagName('select');
for (i=0; i<fields.length; i++) {
SetProperty(fields[i].id, fields[i].value);
}
SetProperty("first_start", "false");
}
//document.getElementById("_content").innerHTML = "<textarea>" + prepeareWidget(GetProperty("widgetpath","")) + "</textarea>";
document.getElementById("_content").innerHTML = prepeareWidget(GetProperty("widgetpath",""));
}
function onHover(obj, src)
{
obj.src = src;
}
function placeWindowButtons(bMinimize, bSettings, bOnTop, bClose)
{
var buttons = "";
if (bMinimize) buttons += '<span onmousedown="MinimizeMaximizeTriger();"><img src="minimize.gif" onMouseOver="onHover(this, \'onminimize.gif\');" onMouseOut="onHover(this, \'minimize.gif\');"></span>';
if (bSettings) buttons += '<span onmousedown="showSettings();"><img src="settings.gif" onMouseOver="onHover(this, \'onsettings.gif\');" onMouseOut="onHover(this, \'settings.gif\');"></span>';
if (bOnTop) buttons += '<span onmousedown="AlwaysOnTopTriger();"><img src="ontop.gif" onMouseOver="onHover(this, \'onontop.gif\');" onMouseOut="onHover(this, \'ontop.gif\');"></span>';
if (bClose) buttons += '<span onmousedown="Close();"><img src="close.gif" onMouseOver="onHover(this, \'onclose.gif\');" onMouseOut="onHover(this, \'close.gif\');"></span>';
buttons += '<span> </span>';
document.getElementById("_window_buttons").innerHTML = buttons;
}
function placeSmoothCorner()
{
var html = "";
var width = 1*window.external.GetProperty("width", 0)-6;
var height = 1*window.external.GetProperty("height", 0)-6;
html += "<img id=_lt src='lt.gif' border=0 style='position:absolute; top:0px; left:0px;'>";
html += "<img id=_rt src='rt.gif' border=0 style='position:absolute; top:0px; left:"+width+"px;'>";
html += "<img id=_rb src='rb.gif' border=0 style='position:absolute; top:"+height+"px; left:"+width+"px;'>";
html += "<img id=_lb src='lb.gif' border=0 style='position:absolute; top:"+height+"px; left:0px;'>";
document.body.innerHTML += html;
}
function moveSmoothCorner(width, height)
{
try{
document.getElementById("_lb").style.top = 1*height-6 + "px";
document.getElementById("_rb").style.top = 1*height-6 + "px";
document.getElementById("_rb").style.left = 1*width-6 + "px";
document.getElementById("_rt").style.left = 1*width-6 + "px";
} catch(err){}
}